<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>注册用户</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" />
    <style>
        .account {
            width: 400px;
            margin: 0 auto;
        }
    </style>
</head>

<body>
    <div class="account">
        <h2 style="text-align: center;">注册用户</h2>
        <form>
            {% for field in form %}
            <div class="form-group">
                {% if field.name == 'code' %}
                <div class="form-group">
                    <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                    <div class="clearfix">
                        <div class="col-md-6" style="padding-left: 0;">{{ field }}</div>
                        <div class="col-md-6"><input id="btnSms" type="button" class="btn btn-default" value="点击获取验证码"></div>
                    </div>
                </div>

                {% else %}
                <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                {{ field }}
                {% endif %}
            </div>
            {% endfor %}
            
            <button type="submit" class="btn btn-primary">注 册</button>
        </form>
    </div>

    <!--{% for field in form %}-->
    <!--<p> {{ field.label }} : {{ field }}</p>-->
    <!--{% endfor %}-->

    <script>
        /* 页面框架加载完后自动执行的函数 */
        $(function () {

        });

        // 点击获取验证码的按钮绑定事件
        function bindClickBtnSms() {
            $('#btnSms').click(function () {
                var mobilePhone = $('#id_mobile_phone').val();
                $.ajax({
                    url: "{% url 'send_sms' %}",
                    type: "GET",
                    data: {moble_phone: mobilePhone, aaa: '123'},
                    success: function (res) {
                        console.log(res)
                    }
                })
            })
        }
    </script>
</body>

</html>